﻿<?php //VSIA ETA HUJNIA DLIA PERENOSKI DANNYH?>
<?php require_once("includes/connection.php"); ?>

<?php

	$query = "SELECT *";
	$query .= " FROM `temppask`";
	$query .= " WHERE `paskatinimaiid`>19999";
	$query .= " AND `paskatinimaiid`<50000";
	// $query .= " WHERE `user`.userid =";
	// $query .= "'".$_GET['userid']."'";
	$result = mysql_query($query, $connection);
	
	echo $query."<br>";	
	$subject = mysql_fetch_array($result);
	print_r ($subject);

do { 

	
	
	$query = "SELECT *";
			$query .= " FROM `user`";
			$query .= " WHERE `user`.bylosnr =";
			$query .= "'".$subject['bylosnr']."'";
	
	$result_set = mysql_query($query, $connection);
			$lopas = mysql_fetch_array($result_set);
	
	
if (isset($lopas['userid'])){
	//echo "pask.rusys:".($subject['paskrusysid'])."<br>";
	$nuobauda = NULL;
	echo $lopas['vardas']." ". $lopas['pavarde']." ". $subject['svarstdata']." gavo nuobauda"."<BR>";
	if	(($subject['paskrusysid'])==6)	{
			$query = "SELECT *";
			$query .= " FROM `nuobaudos`";
			$query .= " WHERE `nuobaudos`.`userid` =";
			$query .= $lopas['userid'];
			$query .= " AND `nuobaudos`.`svarstdata` =";
			$query .= "'".$subject['nuobaudosdata']."'";
			//echo $query."<BR>";
			$result_set = mysql_query($query, $connection);
			$nuobauda = mysql_fetch_array($result_set);
			//echo $nuobauda['nuobaudosid'];
			//echo "<br>";
	};	
	$sql = "INSERT INTO `paskatinimai` (`userid` ,`paskatinimopriezastysid` ,`paskrusysid` ,`svarstdata` ,`nuobaudosid` ,`istaiga`)VALUES (";
				$sql .= $lopas['userid'];
				$sql .= ", ";
			if(!isset($subject['paskatinimopriezastysid'])){$sql .= "NULL";}	else{
				$sql .= $subject['paskatinimopriezastysid'];};
				$sql .= ", ";
			if(!isset($subject['paskrusysid'])){$sql .= "NULL";}	else{
				$sql .= $subject['paskrusysid'];};
				$sql .= ", ";
			
			if(!isset($subject['svarstdata'])){$sql .= "NULL";}	else{	
				$sql .= "'".$subject['svarstdata']."'";};
				$sql .= ", ";
			if(!isset($nuobauda['nuobaudosid'])){$sql .= "NULL";}	else{	
				$sql .= $nuobauda['nuobaudosid'];};
				$sql .= ", ";
			
			if(!isset($subject['istaiga'])){$sql .= "NULL";}	else{		
				$sql .= $subject['istaiga'];};
				
				$sql .= ")";
				
				//echo $sql."<br><br>";
				
				$update = mysql_query($sql, $connection);
					if (!$update) {
						// Display error message.
						echo $sql."<br>";
						echo $subject['nuobaudosid']."SSuka <br><br>";
					}else{
						
						echo $subject['paskatinimaiid']."<BR>";
					};
};
	
	} while ($subject = mysql_fetch_assoc($result)); 	
				// $sql = "UPDATE `migracija` SET ";
				// $sql .= "kelimodata=";
				// $sql .= "'".($_POST['kelimodata'])."'";
				// $sql .= ", fromlovosid=";
				// $sql .= $fromlovosid;
				// $sql .= ", tolovosid=";
				// $sql .= $tolovosid;
				
				// $sql .= ", perkeltas=";
				
				// $sql .= " WHERE `migracija`.`migracijaid` =";
				// $sql .= $_GET['migracijaid'];
				// echo $sql;
				// $result = mysql_query($sql, $connection);
					// if (!$result) {
						// Display error message.
						// $message .= "<p>Migracija table update failed</p>";
						// $message .= "<p>" . mysql_error() . "</p>";
					// }else{
						// $to = "form_prekelimai.php";
						// redirect_to($to);
					// };
					
?>